package application;


import dataStructures.*;
/**
 * @author Carlos Duarte - 43796
 * @author Rafael Florencio - 43829
 */
public class TextProcessorClass implements TextProcessor{
	private static final long serialVersionUID = 0L;
	private ChainedHashTable<String, Text> texts;
	private Dicionario dicionario;
	
	public TextProcessorClass(){
		dicionario = new DicionarioClass();
		texts = new ChainedHashTable<String,Text>();
	}
	
	@Override
	public void addWord(String word) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void addText(String idText, int lines, String[] Linetext) {
		Text aux = texts.insert(idText, new TextClass(idText, lines, dicionario));
		for(int i=0; i<lines; i++){
			aux.addLine(Linetext[i], lines);
		}
	}

	@Override
	public boolean removeText(String idText) {
			if(texts.remove(idText)!=null)
				return true;
			else
				return false;
	}

	@Override
	public String listText(String idText, int minimum, int maximum) {
		return getText(idText).getText(minimum, maximum);
	}

	@Override
	public Iterator<Word> listWordByType(String idText, String type) {
		return getText(idText).listWordByType(type);
	}

	@Override
	public int countTimes(String idText, String word) {
		return getText(idText).countWord(word);
	}

	@Override
	public boolean wordExistsDictionary(String word) {
		if(dicionario.verifyWord(word))
			return true;
		else
			return false;
	}

	@Override
	public void addDictionary(String word) {
		dicionario.addWord(word);
		clearTexts();
	}

	private void clearTexts() {
				texts.removeAll();
	}

	@Override
	public boolean hasText(String id) {
		if(texts.isEmpty())
			return false;
		else
			return texts.find(id) != null;
	}
	
	public Text getText(String id){
		
		return texts.find(id);
	}
	
}
